<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="panel panel-default operation" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
    </div>
</div>

<div class="table_div">
    <div id="searchParam" shiro:hasPermission="sysJob:list">
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input type="text" id="jobId" class="layui-input" autocomplete="off" placeholder="请输入任务id">
            </div>

            <div class="layui-input-inline ">
                <button class="layui-btn" onclick="search()" id="search">查询</button>
            </div>
        </div>

    </div>
    <table class="layui-table" id="showTable" lay-filter="showTable"></table>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="batchDeleted" shiro:hasPermission="sysJob:delete">清空</button>
    </div>
</script>
</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;

    layui.use(['table', 'layer', 'laydate'], function () {

        //加载table
        tableIns1 = table.render({
            elem: '#showTable'
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , url: '/sysJobLog/listByPage' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', title: '任务日志id', sort: true},
                    {field: 'jobId', title: '任务id', sort: true},
                    {field: 'beanName', title: 'spring bean名称', sort: true},
                    {field: 'params', title: '参数', sort: true},
                    {
                        field: 'status', title: '任务状态', width: 110, sort: true, templet: function (item) {
                            if (item.status === 1) {
                                return '  <button type="button"  class="layui-btn  layui-btn-xs layui-btn-danger">失败</button>';
                            }
                            if (item.status === 0) {
                                return '  <button type="button"  class="layui-btn   layui-btn-xs">成功</button>';
                            }
                        }
                    },
                    {field: 'error', title: '失败信息', sort: true},
                    {field: 'times', title: '耗时(单位：毫秒)', sort: true},
                    {field: 'createTime', title: '创建时间', sort: true}]
            ]
            , toolbar: '#toolbar'
        });

        //表头工具
        table.on('toolbar(showTable)', function (obj) {
            switch (obj.event) {
                case 'batchDeleted':
                    layer.open({
                        content: "确定要清空么?",
                        yes: function (index, layero) {
                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                            CoreUtil.sendDelete("/sysJobLog/delete", {}, function (res) {
                                layer.msg(res.msg, {time: 1000}, function () {
                                    search();
                                });
                            });
                        }
                    });
                    break;
            }
            ;
        });

        //返回
        $("#btn_cancel").click(function () {
            $(".table_div").show();
            $(".operation").hide();
            return false;
        });
    });

    //执行查询
    function search() {
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                jobId: $("#jobId").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    };
</script>